import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

class TestC:
    def test1(self):
        # 创建驱动对象
        driver = webdriver.Edge()
        # 打开 注册A
        driver.get('file:///D:/pagetest/page/%E6%B3%A8%E5%86%8CA.html')
        time.sleep(2)
        # 点击 访问 新浪 网站
        driver.find_element(By.CSS_SELECTOR,'#fw').click()
        time.sleep(2)
        # 对 网址 做断言
        assert driver.current_url == 'file:///D:/pagetest/page/%E6%B3%A8%E5%86%8CA.html'
        # 对 网页信息 做断言
        assert '手机新浪网' in driver.page_source
        # 睡3秒 关闭网页
        time.sleep(3)
        driver.quit()
    def test2(self):
        # 创建驱动对象
        driver1 = webdriver.Edge()
        # 打开 注册A
        driver1.get('file:///D:/pagetest/注册A.html')
        time.sleep(2)
        # 悬停 到 菜单
        action = ActionChains(driver1)
        b = driver1.find_element(By.CSS_SELECTOR,'#item')
        action.move_to_element(b)
        action.perform()
        time.sleep(2)
        # 点击 淘宝
        c = driver1.find_element(By.CSS_SELECTOR,'#itemA')
        action.click(c)
        action.perform()
        time.sleep(2)
        # 对 网址 做断言
        assert driver1.current_url == 'https://www.taobao.com/'
        # 对 网页信息 做断言
        assert '免费注册' in driver1.page_source
        # 睡3秒 关闭网页
        time.sleep(3)
        driver1.quit()
    def test3(self):
        # 创建驱动对象
        driver2 = webdriver.Edge()
        # 打开 注册A
        driver2.get('file:///D:/pagetest/注册A.html')
        time.sleep(2)
        # 悬停 到 菜单
        action = ActionChains(driver2)
        a = driver2.find_element(By.CSS_SELECTOR,'#item')
        action.move_to_element(a)
        action.perform()
        # 点击 京东
        b = driver2.find_element(By.CSS_SELECTOR,'#itemB')
        action.click(b)
        action.perform()
        time.sleep(2)
        # 对 网址 做断言
        assert driver2.current_url == 'https://www.jd.com/'
        # 对 网页信息 做断言
        assert '京东超市' in driver2.page_source
        # 睡3秒 关闭网页
        time.sleep(3)
        driver2.quit()
    def test4(self):
        # 创建驱动对象
        driver3 = webdriver.Edge()
        # 打开 注册A
        driver3.get('file:///D:/pagetest/注册A.html')
        time.sleep(2)
        # 悬停 到 菜单
        action = ActionChains(driver3)
        d = driver3.find_element(By.CSS_SELECTOR,'#item')
        action.move_to_element(d)
        action.perform()
        time.sleep(2)
        # 点击 豆瓣
        driver3.find_element(By.XPATH,'//*[@id="itemC"]').click()
        time.sleep(2)
        a = driver3.window_handles[1]
        driver3.switch_to.window(a)
        # 对 网址 做断言
        assert driver3.current_url == 'https://movie.douban.com/'
        # 对 网页信息 做断言
        assert '豆瓣电影' in driver3.page_source
        # 睡3秒 关闭网页
        time.sleep(3)
        driver3.quit()

